﻿#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using Memo.Electricity.Game;

namespace Memo.Electricity.Editor
{
    [CustomEditor(typeof(PlayerManager))]
    public class PlayerStartEditor : UnityEditor.Editor
    {
        private PlayerManager mPlayerManager = null;
        private void OnEnable()
        {
            mPlayerManager = target as PlayerManager;
        }

        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
        }

        private void OnSceneGUI()
        {
            Vector3 player1StartPos = mPlayerManager.Player1StartPos;
            Vector3 player2StartPos = mPlayerManager.Player2StartPos;
            Handles.color = Color.blue;
            Handles.DrawSolidDisc(player1StartPos, Vector3.forward, 0.2f);//蓝色代表player1
            Handles.color = Color.red;
            Handles.DrawSolidDisc(player2StartPos, Vector3.forward, 0.2f);//红色代表player2
            Vector3 newWorld1 = Handles.PositionHandle(player1StartPos, Quaternion.identity);
            Vector3 newWorld2 = Handles.PositionHandle(player2StartPos, Quaternion.identity);
            if (newWorld1!=player1StartPos)
            {
                Undo.RecordObject(target, "Change node property");
                mPlayerManager.Player1StartPos = newWorld1;
            }
            if (newWorld2 != player1StartPos)
            {
                Undo.RecordObject(target, "Change node property");
                mPlayerManager.Player2StartPos = newWorld2;
            }
        }
    }
}
#endif